﻿<UserControl
	x:Class="JsonEditor.JsonEditorControl"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
	xmlns:local="clr-namespace:JsonEditor"
	
	FontSize="12">

	<UserControl.Resources>

		<local:ItemTemplateSelector x:Key="ItemTemplateSelector" />

		<local:JTokenToIndexConverter x:Key="JTokenToIndexConverter" />

		<controls:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

		<local:JObjectSortPropertyConverter x:Key="JObjectSortPropertyConverter" />

		<local:JObjectToJPropertiesCollectionConverter x:Key="JObjectToJPropertiesCollectionConverter" />

		<local:JTokenToAncestorsConverter x:Key="JTokenToAncestorsConverter" />

		<Style x:Key="JValueTextBlockStyle" TargetType="{x:Type TextBlock}">
			<Setter Property="Text" Value="{Binding Value, TargetNullValue='&lt;null&gt;'}" />
			<Setter Property="SnapsToDevicePixels" Value="True" />

			<Style.Triggers>
				<DataTrigger Binding="{Binding Type}" Value="String">
					<Setter Property="Text" Value="{Binding Path=Value, TargetNullValue='&lt;null&gt;', StringFormat='&quot;\{0\}&quot;'}" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<HierarchicalDataTemplate x:Key="JPropertyWithArrayTemplate" ItemsSource="{Binding Value}" ItemTemplateSelector="{StaticResource ItemTemplateSelector}">
			<Border Tag="{Binding Path=., RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}" SnapsToDevicePixels="True">
				<DockPanel>
					<Ellipse Fill="#df7ce0" Stroke="Gray" StrokeThickness="0.5" Height="12" Width="12" VerticalAlignment="Center" Margin="0,0,5,0" />
					<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
						<TextBlock Text="{Binding Name}" />
						<TextBlock Text="{Binding Value.Count, StringFormat=' [\{0\}]'}"  />
					</StackPanel>
					<DockPanel.InputBindings>
						<MouseBinding Gesture="LeftDoubleClick" Command="{Binding Tag.EditPropertyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border}}}" CommandParameter="{Binding}" />
					</DockPanel.InputBindings>
				</DockPanel>

				<Border.ContextMenu>
					<ContextMenu>
						<MenuItem Header="Copy" Command="{Binding PlacementTarget.Tag.CopyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Edit" Command="{Binding PlacementTarget.Tag.EditPropertyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="New">
							<MenuItem Header="Object" Command="{Binding PlacementTarget.Tag.NewObjectCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
							<MenuItem Header="Value" Command="{Binding PlacementTarget.Tag.NewValueCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						</MenuItem>
						<MenuItem Header="Paste" Command="{Binding PlacementTarget.Tag.PasteCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Remove" Command="{Binding PlacementTarget.Tag.RemoveCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Remove All" Command="{Binding PlacementTarget.Tag.RemoveAllCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
					</ContextMenu>
				</Border.ContextMenu>
			</Border>
		</HierarchicalDataTemplate>

		<HierarchicalDataTemplate x:Key="JPropertyWithObjectTemplate" ItemsSource="{Binding Value, Converter={StaticResource JObjectSortPropertyConverter}}" ItemTemplateSelector="{StaticResource ItemTemplateSelector}">
			<Border Tag="{Binding Path=., RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}" SnapsToDevicePixels="True">
				<DockPanel>
					<Rectangle Fill="#f4d15c" Stroke="Gray" StrokeThickness="0.5" Height="12" Width="12" VerticalAlignment="Center" Margin="0,0,5,0" />
					<TextBlock Text="{Binding Name}" VerticalAlignment="Center" />
					<DockPanel.InputBindings>
						<MouseBinding Gesture="LeftDoubleClick" Command="{Binding Tag.EditPropertyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border}}}" CommandParameter="{Binding}" />
					</DockPanel.InputBindings>
				</DockPanel>

				<Border.ContextMenu>
					<ContextMenu>
						<MenuItem Header="Copy" Command="{Binding PlacementTarget.Tag.CopyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Edit" Command="{Binding PlacementTarget.Tag.EditPropertyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="New Property" Command="{Binding PlacementTarget.Tag.NewPropertyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Paste" Command="{Binding PlacementTarget.Tag.PasteCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Remove" Command="{Binding PlacementTarget.Tag.RemoveCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Remove All" Command="{Binding PlacementTarget.Tag.RemoveAllCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
					</ContextMenu>
				</Border.ContextMenu>
			</Border>
		</HierarchicalDataTemplate>

		<DataTemplate x:Key="JPropertyWithValueTemplate">
			<Border Tag="{Binding Path=., RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}" SnapsToDevicePixels="True">
				<DockPanel>
					<Rectangle Fill="#87bcec" Stroke="Gray" StrokeThickness="0.5" Height="6" Width="12" VerticalAlignment="Center" Margin="0,0,5,0" />
					<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
						<TextBlock Text="{Binding Name}" />
						<TextBlock Text=": " />
						<TextBlock DataContext="{Binding Value}" Style="{StaticResource JValueTextBlockStyle}" />
					</StackPanel>
					<DockPanel.InputBindings>
						<MouseBinding Gesture="LeftDoubleClick" Command="{Binding Tag.EditPropertyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border}}}" CommandParameter="{Binding}" />
					</DockPanel.InputBindings>
				</DockPanel>

				<Border.ContextMenu>
					<ContextMenu>
						<MenuItem Header="Copy">
							<MenuItem Header="Property" Command="{Binding PlacementTarget.Tag.CopyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
							<MenuItem Header="Name" Command="{Binding PlacementTarget.Tag.CopyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding Name}" />
							<MenuItem Header="Value" Command="{Binding PlacementTarget.Tag.CopyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding Value}" />
						</MenuItem>
						<MenuItem Header="Edit" Command="{Binding PlacementTarget.Tag.EditPropertyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Remove" Command="{Binding PlacementTarget.Tag.RemoveCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
					</ContextMenu>
				</Border.ContextMenu>
			</Border>
		</DataTemplate>

		<HierarchicalDataTemplate x:Key="JArrayTemplate" ItemsSource="{Binding}" ItemTemplateSelector="{StaticResource ItemTemplateSelector}">
			<Border Tag="{Binding ., RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}" SnapsToDevicePixels="True">

				<Border.ContextMenu>
					<ContextMenu>
						<MenuItem Header="Copy" Command="{Binding PlacementTarget.Tag.CopyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="New">
							<MenuItem Header="Object" Command="{Binding PlacementTarget.Tag.NewObjectCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
							<MenuItem Header="Value" Command="{Binding PlacementTarget.Tag.NewValueCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						</MenuItem>
						<MenuItem Header="Paste" Command="{Binding PlacementTarget.Tag.PasteCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Remove" Command="{Binding PlacementTarget.Tag.RemoveCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Remove All" Command="{Binding PlacementTarget.Tag.RemoveAllCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
					</ContextMenu>
				</Border.ContextMenu>
				<DockPanel>
					<Ellipse Fill="#df7ce0" Stroke="Gray" StrokeThickness="0.5" Height="12" Width="12" VerticalAlignment="Center" Margin="0,0,2.5,0" />
					<TextBlock Text="{Binding Count, StringFormat=' [\{0\}]'}"  />
				</DockPanel>

			</Border>
		</HierarchicalDataTemplate>

		<HierarchicalDataTemplate x:Key="JObjectTemplate" ItemsSource="{Binding Converter={StaticResource JObjectSortPropertyConverter}}" ItemTemplateSelector="{StaticResource ItemTemplateSelector}">
			<Border Tag="{Binding Path=., RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}" SnapsToDevicePixels="True">
				<Border.ContextMenu>
					<ContextMenu>
						<MenuItem Header="Copy" Command="{Binding PlacementTarget.Tag.CopyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="New Property" Command="{Binding PlacementTarget.Tag.NewPropertyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Paste" Command="{Binding PlacementTarget.Tag.PasteCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Remove" Command="{Binding PlacementTarget.Tag.RemoveCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Remove All" Command="{Binding PlacementTarget.Tag.RemoveAllCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
					</ContextMenu>
				</Border.ContextMenu>

				<DockPanel>
					<Rectangle Fill="#f4d15c" Stroke="Gray" StrokeThickness="0.5" Height="12" Width="12" Margin="0,0,5,0" VerticalAlignment="Center" />
					<TextBlock Text="{Binding Converter={StaticResource JTokenToIndexConverter}, StringFormat='[\{0\}]', TargetNullValue=''}" />
				</DockPanel>
			</Border>
		</HierarchicalDataTemplate>

		<DataTemplate x:Key="JValueTemplate">
			<Border Tag="{Binding Path=., RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}" SnapsToDevicePixels="True">
				<DockPanel>					
					<Ellipse Fill="Black" Stroke="Gray" StrokeThickness="0.5" Height="6" Width="6" VerticalAlignment="Center" Margin="3,0,8,0" />
					<TextBlock Text="{Binding Converter={StaticResource JTokenToIndexConverter}, StringFormat='[\{0\}]: ', TargetNullValue=''}" />
					<TextBlock Style="{StaticResource JValueTextBlockStyle}">
						<TextBlock.InputBindings>
							<MouseBinding Gesture="LeftDoubleClick" Command="{Binding Tag.EditValueCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border}}}" CommandParameter="{Binding}" />
						</TextBlock.InputBindings>
					</TextBlock>
				</DockPanel>

				<Border.ContextMenu>
					<ContextMenu>
						<MenuItem Header="Copy" Command="{Binding PlacementTarget.Tag.CopyCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Edit" Command="{Binding PlacementTarget.Tag.EditValueCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
						<MenuItem Header="Remove" Command="{Binding PlacementTarget.Tag.RemoveCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" CommandParameter="{Binding}" />
					</ContextMenu>
				</Border.ContextMenu>
			</Border>
		</DataTemplate>

		<DataTemplate x:Key="ErrorTemplate">
			<TextBlock Text="&lt;Not Supported&gt;" Foreground="Red" />
		</DataTemplate>

		<Style TargetType="Thumb">
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="Thumb">
						<Rectangle Fill="Transparent" />
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>

		<DataTemplate x:Key="JTokenLinkTemplate">
			<Button SnapsToDevicePixels="True" Height="16" Cursor="Hand" Command="{Binding Path=NavigateToCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}" CommandParameter="{Binding}">
				<Button.Template>
					<ControlTemplate TargetType="{x:Type Button}">
						<Grid>
							<Border x:Name="UnderlineBorder" Visibility="Collapsed" BorderBrush="Gray" Background="Transparent" BorderThickness="0,0,0,0.5" Margin="17,0,0,0" SnapsToDevicePixels="True" />
							<ContentPresenter Content="{Binding}" ContentTemplateSelector="{StaticResource ItemTemplateSelector}" />
						</Grid>
						<ControlTemplate.Triggers>
							<Trigger Property="IsMouseOver" Value="True">
								<Setter TargetName="UnderlineBorder" Property="Visibility" Value="Visible" />
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Button.Template>
			</Button>
		</DataTemplate>

		<DataTemplate x:Key="BreadcrumbTemplate">
			<ItemsControl ItemsSource="{Binding Converter={StaticResource JTokenToAncestorsConverter}}" UseLayoutRounding="True">
				<ItemsControl.ItemsPanel>
					<ItemsPanelTemplate>
						<WrapPanel />
					</ItemsPanelTemplate>
				</ItemsControl.ItemsPanel>
				<ItemsControl.ItemTemplate>
					<DataTemplate>
						<StackPanel Orientation="Horizontal">
							<ContentPresenter Content="{Binding}" ContentTemplate="{StaticResource JTokenLinkTemplate}" />
							<Image Source="/JsonEditor;component/Images/tab_right.png" Height="16" Width="16" VerticalAlignment="Center" />
						</StackPanel>
					</DataTemplate>
				</ItemsControl.ItemTemplate>
			</ItemsControl>
		</DataTemplate>

		<Style TargetType="{x:Type ListBoxItem}">
			<Setter Property="Focusable" Value="False"/>
		</Style>

		<Style TargetType="{x:Type ListBox}" BasedOn="{StaticResource {x:Type ListBox}}">
			<Style.Triggers>
				<Trigger Property="HasItems" Value="False">
					<Setter Property="Template">
						<Setter.Value>
							<ControlTemplate TargetType="{x:Type ListBox}">
								<Border Background="White" UseLayoutRounding="True" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
									<TextBlock Text="No Items" HorizontalAlignment="Center" VerticalAlignment="Center" />
								</Border>
							</ControlTemplate>
						</Setter.Value>
					</Setter>
				</Trigger>
			</Style.Triggers>
		</Style>
	</UserControl.Resources>

	<Grid>
		<DockPanel Margin="5">

			<!--Breadcumbs and Search TextBox-->
			<DockPanel DockPanel.Dock="Top" Margin="0,0,0,3">
				<StackPanel Orientation="Horizontal" DockPanel.Dock="Right" Height="20" VerticalAlignment="Top" Margin="5,0,0,0">
					<Border SnapsToDevicePixels="True" BorderThickness="1" BorderBrush="Gray" Background="White">
						<Grid Background="White" Width="100">
							<TextBlock Margin="5,2" Text="Search" Visibility="{Binding ElementName=SearchTextBox, Path=Text.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}}" Foreground="Gray" FontStyle="Italic" IsHitTestVisible="False"/>
							<TextBox x:Name="SearchTextBox" BorderThickness="0" Background="Transparent" Padding="0,2,0,0"/>
						</Grid>
					</Border>
					<Button Margin="2.5,0,0,0" Command="{Binding SearchCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}" CommandParameter="{Binding ElementName=SearchTextBox, Path=Text}" IsDefault="{Binding ElementName=SearchTextBox, Path=IsKeyboardFocused}">
						<Button.Content>
							<Image Source="/JsonEditor;component/Images/search.png" Height="14" Width="14" />
						</Button.Content>
					</Button>
				</StackPanel>

				<ContentPresenter Content="{Binding ElementName=RootTreeview, Path=SelectedItem}" ContentTemplate="{StaticResource BreadcrumbTemplate}" />

			</DockPanel>

			<!--Search Results-->
			<Border DockPanel.Dock="Bottom" Height="{Binding SearchResultHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}" BorderBrush="Gray" BorderThickness="1" SnapsToDevicePixels="True" Visibility="{Binding SearchResultsVisbility, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}">
				<DockPanel>
					<Border Height="20" BorderBrush="Gray" BorderThickness="0,0,0,1" DockPanel.Dock="Top" SnapsToDevicePixels="True" Padding="3,0,3,0">
						<DockPanel>
							<Button DockPanel.Dock="Right" Height="16" Width="16" Command="{Binding ToggleSearchResultsCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}" CommandParameter="Collapsed">
								<Button.Content>
									<Path Margin="2" Fill="Black" Stretch="Fill" Data="F1 M 6.742676,3.852539 L 9.110840,1.559570 L 8.910645,0.500000 L 6.838379,0.500000 L 4.902832,2.435547 L 2.967285,0.500000 L 0.895020,0.500000 L 0.694824,1.559570 L 3.062988,3.852539 L 0.527832,6.351563 L 0.689941,7.600586 L 2.967285,7.600586 L 4.897949,5.575195 L 6.854004,7.600586 L 9.115723,7.600586 L 9.277832,6.351563 L 6.742676,3.852539 Z" VerticalAlignment="Center" Opacity="0.5" />
								</Button.Content>
							</Button>

							<TextBlock Text="Search Results:" VerticalAlignment="Center"  />
						</DockPanel>
					</Border>

					<ListBox ItemsSource="{Binding FoundItems, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}" ItemTemplate="{StaticResource BreadcrumbTemplate}" BorderThickness="0" />
				</DockPanel>
			</Border>

			<Thumb x:Name="PART_SearchResultThumb" DockPanel.Dock="Bottom" Height="3" HorizontalAlignment="Stretch" Cursor="SizeNS" Visibility="{Binding SearchResultsVisbility, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}" />

			<Grid>
				<Grid.Resources>
					<Style x:Key="HorizontalSplitterStyle" TargetType="{x:Type GridSplitter}">
						<Setter Property="HorizontalAlignment" Value="Stretch" />
						<Setter Property="VerticalAlignment" Value="Center" />
						<Setter Property="Height" Value="3" />
						<Setter Property="Background" Value="Transparent" />
					</Style>
					<Style x:Key="VerticalSplitterStyle" TargetType="{x:Type GridSplitter}">
						<Setter Property="HorizontalAlignment" Value="Center" />
						<Setter Property="VerticalAlignment" Value="Stretch" />
						<Setter Property="Width" Value="3" />
						<Setter Property="Background" Value="Transparent" />
					</Style>
				</Grid.Resources>

				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="2*" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="1*" />
				</Grid.ColumnDefinitions>

				<TreeView x:Name="RootTreeview" Padding="5">
					<TreeViewItem Header="{Binding}" HeaderTemplateSelector="{StaticResource ItemTemplateSelector}" ItemsSource="{Binding Converter={StaticResource JObjectSortPropertyConverter}}" ItemTemplateSelector="{StaticResource ItemTemplateSelector}" IsExpanded="True" />

					<TreeView.InputBindings>
						<KeyBinding Key="Delete" Command="{Binding Path=RemoveCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}" CommandParameter="{Binding ElementName=RootTreeview, Path=SelectedItem}" />
					</TreeView.InputBindings>
				</TreeView>

				<GridSplitter Style="{StaticResource VerticalSplitterStyle}" Grid.Column="1" />

				<DockPanel Grid.Column="2">
					<Button
						Margin="0,3,0,0"
						HorizontalAlignment="Stretch" 
						DockPanel.Dock="Bottom"
						Visibility="{Binding Path=IsUpdateAvailable, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}, Converter={StaticResource BooleanToVisibilityConverter}}"
						Command="{Binding Path=ViewUpdateCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}"
						Content="Update Available" />

					<TabControl DataContext="{Binding ElementName=RootTreeview, Path=SelectedItem}">
						<TabControl.Resources>

							<Style TargetType="{x:Type ListBox}" BasedOn="{StaticResource {x:Type ListBox}}">
								<Setter Property="ItemTemplate" Value="{StaticResource JTokenLinkTemplate}" />
							</Style>

						</TabControl.Resources>

						<TabItem Header="All">
							<Grid>
								<Grid.RowDefinitions>
									<RowDefinition />
									<RowDefinition Height="Auto" />
									<RowDefinition />
									<RowDefinition Height="Auto" />
									<RowDefinition />
								</Grid.RowDefinitions>

								<ListBox ItemsSource="{Binding Converter={StaticResource JObjectToJPropertiesCollectionConverter}, ConverterParameter=Values}" Grid.Row="0" />

								<GridSplitter Style="{StaticResource HorizontalSplitterStyle}" Grid.Row="1" />
								<ListBox ItemsSource="{Binding Converter={StaticResource JObjectToJPropertiesCollectionConverter}, ConverterParameter=Objects}" Grid.Row="2" />

								<GridSplitter Style="{StaticResource HorizontalSplitterStyle}" Grid.Row="3" />
								<ListBox ItemsSource="{Binding Converter={StaticResource JObjectToJPropertiesCollectionConverter}, ConverterParameter=Arrays}" Grid.Row="4" />
							</Grid>
						</TabItem>

						<TabItem Header="Properties">
							<ListBox ItemsSource="{Binding Converter={StaticResource JObjectToJPropertiesCollectionConverter}, ConverterParameter=Values}" Grid.Row="0" />
						</TabItem>

						<TabItem Header="Objects">
							<ListBox ItemsSource="{Binding Converter={StaticResource JObjectToJPropertiesCollectionConverter}, ConverterParameter=Objects}" Grid.Row="2" />
						</TabItem>

						<TabItem Header="Arrays">
							<ListBox ItemsSource="{Binding Converter={StaticResource JObjectToJPropertiesCollectionConverter}, ConverterParameter=Arrays}" Grid.Row="4" />
						</TabItem>

					</TabControl>
				</DockPanel>

			</Grid>
		</DockPanel>

		<!--Property Editor-->
		<Grid Visibility="{Binding Path=EditValueVisibility, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}">
			<Border Background="Black" Opacity="0.25" />
			<Border x:Name="PART_PropertyEditor" Height="200" Width="300" CornerRadius="5" BorderThickness="1" BorderBrush="Gray" Background="White" RenderTransformOrigin="0,0">
				<Border.RenderTransform>
					<TranslateTransform x:Name="PART_DragTranslateTransform" />
				</Border.RenderTransform>
				<DockPanel Margin="5">
					<Border CornerRadius="5,5,0,0" Background="LightGray" DockPanel.Dock="Top">
						<Grid>
							<TextBlock Text="Edit" VerticalAlignment="Center" Margin="5" />
							<Thumb x:Name="PART_DragThumb" />
						</Grid>
					</Border>

					<Thumb x:Name="PART_ResizePropertyEditorThumb" Cursor="SizeNWSE" Height="5" Width="5" HorizontalAlignment="Right" DockPanel.Dock="Bottom" Background="Black" />

					<DockPanel Margin="5,5,5,0" DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:JsonEditorControl}}}">

						<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" DockPanel.Dock="Bottom" Margin="0,10,0,0">
							<Button Height="30" Width="70" Content="Ok" Command="{Binding OkCommand}" Margin="0,0,5,0" />
							<Button Height="30" Width="70" Content="Cancel" Command="{Binding CancelCommand}" />
						</StackPanel>

						<DockPanel DataContext="{Binding EditedJToken}">
							<DockPanel.Resources>
								<Style TargetType="{x:Type DockPanel}">
									<Setter Property="Margin" Value="0,5,0,0" />
									<Setter Property="MinHeight" Value="20" />
								</Style>
							</DockPanel.Resources>

							<DockPanel Margin="0,0,0,0" Visibility="{Binding IsProperty, Converter={StaticResource BooleanToVisibilityConverter}}" DockPanel.Dock="Top">
								<TextBlock Text="Name:" Width="35" />
								<TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}" />
							</DockPanel>

							<DockPanel DockPanel.Dock="Top">
								<TextBlock Text="Type:" Width="35" />

								<CheckBox x:Name="IsNullCheckBox" Content="Null" IsChecked="{Binding IsNull}" DockPanel.Dock="Right" VerticalAlignment="Center" Margin="5,0,0,0" VerticalContentAlignment="Center" />

								<ComboBox SelectedItem="{Binding Type}" ItemsSource="{Binding ValueTypes}" />
							</DockPanel>

							<DockPanel Visibility="{Binding CanEditValue, Converter={StaticResource BooleanToVisibilityConverter}}">
								<TextBlock Text="Value:" Width="35" VerticalAlignment="Top" Margin="0,4,0,0"/>
								<TextBox AcceptsReturn="True" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
									<TextBox.Style>
										<Style TargetType="{x:Type TextBox}">
											<Setter Property="Text" Value="{Binding Value, UpdateSourceTrigger=PropertyChanged}" />

											<Style.Triggers>
												<DataTrigger Binding="{Binding ElementName=IsNullCheckBox, Path=IsChecked}" Value="True">
													<Setter Property="IsEnabled" Value="False" />
													<Setter Property="Text" Value="" />
												</DataTrigger>
											</Style.Triggers>
										</Style>
									</TextBox.Style>
								</TextBox>
							</DockPanel>

						</DockPanel>
					</DockPanel>
				</DockPanel>
			</Border>
		</Grid>
	</Grid>

</UserControl>
